import { getCookie } from '@/plugins/utils';
import Layout from "../views/user/Layout";

const userRoutes = [
    {
        path: '/user',
        beforeEnter: (to, from, next) => {
            // 未登录，重定向到登录页面
            if(!getCookie('USER_TOKEN')){
                next('/?redirect=' + to.fullPath);
                return false
            }
            next()
        },
        component: Layout,
        children: [
            {
                path: '',
                meta: {
                    title: '欢迎使用'
                },
                component: () => import('@/views/user/Index')
            },
        ]
    },
    {
        path: '/user/user_mg',
        redirect: '/user',
        meta: {
            name: '用户管理'
        },
        component: Layout,
        children: [
            {
                path: '/user/user_mg/school',
                meta: {
                    name: '学校管理',
                    title: '学校管理'
                },
                component: () => import('@/views/user/user_management/school/Index')
            },
            {
                path: 'school/:id',
                meta: {
                    title: '详情'
                },
                component: () => import('@/views/user/user_management/school/Detail')
            },
            {
                path: '/user/user_mg/class',
                meta: {
                    name: '班级管理',
                    title: '班级管理'
                },
                component: () => import('@/views/user/user_management/class/Index')
            },
            {
                path: 'class/:id',
                meta: {
                    title: '详情'
                },
                component: () => import('@/views/user/user_management/class/Detail')
            },
        ]
    },
    {
        path: '/user/notice_mg',
        redirect: '/user',
        meta: {
            name: '公告管理'
        },
        component: Layout,
        children: [
            {
                path: '/user/notice_mg/notice',
                meta: {
                    name: '公告列表',
                    title: '公告列表'
                },
                component: () => import('@/views/user/notice_management/notice/Index')
            },
            {
                path: 'notice/:id',
                meta: {
                    title: '详情'
                },
                component: () => import('@/views/user/notice_management/notice/Detail')
            },
            {
                path: '/user/notice_mg/message',
                meta: {
                    name: '消息通知',
                    title: '消息通知'
                },
                component: () => import('@/views/user/notice_management/message/Index')
            },
            {
                path: 'message/:id',
                meta: {
                    title: '详情'
                },
                component: () => import('@/views/user/notice_management/message/Detail')
            },
        ]
    }
];

export default userRoutes